草庐IT

COM 引用计数

全部标签

go - "Github.com"go 包未显示在 Bitbucket 的远程存储库中

当我将我的go代码推送到我的远程bitbucket存储库时,我没有在github.com包文件夹中看到我的文件,而是看到了这个(这是我的bitbucket存储库的屏幕截图,我希望在那里找到我的go文件):我使用此命令将我的代码推送到我的远程存储库:gitadd.gitcommit-m"message"gitpush-uoriginmaster当我登录到我的Bitbucket帐户时,我希望在“drakecheckin/src/github.com/coopernurse”目录中看到我的go文件。但是我没有看到我的go文件,而是看到一个指向一堆字符+数字的箭头。

arrays - 即使初始化也没有指针取消引用

我的目标是声明一个空的二维数组,然后在每次do()运行时对其进行初始化并填充值。问题是即使我正在初始化数组,我也会得到一个nil指针取消引用。这是我试图在服务器模拟器上完成的一个简单版本。packagemainimport"fmt"typeSrvstruct{A*[][]int}func(sSrv)init(){arr:=make([][]int,0)*s.A=arr}funcmain(){s:=Srv{nil}s.init()printSlice(*s.A)do(s.A)do(s.A)}funcprintSlice(s[][]int){fmt.Printf("len=%dcap=%d

go - Go中的Supertype如何引用Subtype

Go不支持多态性。如果要在通用类型的保护伞下传递特定类型,则它无法在Go中工作。以下一段代码抛出错误。在Go中实现相同功能的最佳方法是什么?packagemainimport("fmt")typeparentstruct{parentIDstring}typechild1struct{parentchild1IDstring}typechild2struct{parentchild2IDstring}typechildCollectionstruct{collection[]parent}func(c*childCollection)appendChild(pparent){c.col

go - 通过范围函数中的地址引用

我有一个定义如下的OuterStruct结构。我正在使用该函数初始化OuterStruct->InnerStruct值name和Var1insetup1()和Var1在setup2()中。在setup2()中分配的值总是nil因为它是按值引用它的。如何使用在这里引用我的地址?typeInnerStructstruct{NamestringVar1*api.Var1Var2*ap1.Var2}typeOuterStructstruct{opNamestringMyData[]InnerStructLogDirstring}func(obj*OuterStruct)Setup2(){for

go - 指针引用未存储在我的 go 程序中的结构中

我是go-lang的新手,我试图弄清楚如何正确地使用结构和依赖注入(inject)。我有点卡住了,因为我无法正确存储对另一个结构的引用。这是我生成CommandController的方法。存在对iris.Application的有效引用。funcProvideCommandController(application*iris.Application,commandRepositorycommand.CommandRepository)(*interfaces.CommandController,error){commandController:=interfaces.CommandC

variables - 使用其他变量中的数据引用go中的变量?

我对go/编码比较陌生。我希望能够通过使用变量来引用变量。vara=make([]int,0)varb=make([]int,0)varc=make([]int,0)我定义了一些sliceset:=input.Ask("Whichsetwouldyouliketoinputto(a,b,c):")fortrue{num:=input.Ask("Number:")strings.toLower(set)=append(strings.toLower(set),num)}我希望“strings.tolower”部分输出一个字符串,它确实如此,这将允许我选择我定义的变量之一。

http - 运行一个简单的服务器,但计数器似乎增加了 3,为什么?

这个问题在这里已经有了答案:Whythissimplewebserveriscalledevennumbertimes?(1个回答)关闭6年前。我这里有这个小服务器。目的是如果我访问localhost:8000/*它应该将counter加1,如果我访问localhost:8000/count,它应该显示counter。发生的一件奇怪的事情是,似乎每次我访问localhost:8000时,计数器都会增加3。所以我会转到localhost:8000/count和counter将在3,然后我访问localhost:8000,然后再次访问localhost:8000/count,counter

string - golang int 对字符串的引用

请帮助我理解这一点,也许我做错了什么。funcmain(){x:=6y:=&xfmt.Println("x:",x,",y:",*y,"stringy:",string(*y))}返回:x:6,y:6stringy:为什么string(*y)不返回6? 最佳答案 specificationsays:ConvertingasignedorunsignedintegervaluetoastringtypeyieldsastringcontainingtheUTF-8representationoftheinteger.表达式string

go - 从另一个包引用结构域

我具有以下文件夹结构:.├──Makefile├──README.md├──myproject│  ├──handlers│  │  └──authorize_handler.go│  ├──models│  │  ├──id_token.go│  ├──server.go我尝试从authorize_handler.go引用IdToken.idType文件中的id_token.go字段。authorize_handler.gopackagehandlersimport("encoding/json""log""net/http""myproject/models")funcAuthor

测试 HTTP 请求时出现 Nil 取消引用错误

我正在尝试在我的Go库中测试HTTP请求。进行调用的对象通过依赖注入(inject)接受HTTP客户端对象,因此在我的测试中,我像这样模拟HTTP客户端:funcTestMyObject(t*testing.T){server:=httptest.NewServer(http.HandlerFunc(func(whttp.ResponseWriter,r*http.Request){w.WriteHeader(200)w.Header().Set("Content-Type","application/json")fmt.Fprintln(w,mockJSONResponse)}))d